package com.yh.controller;

import com.yh.javabean.User;
import com.yh.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @Auther: als
 * @Date: 2024/5/31 - 05 - 31 - 12:11
 * @Description: com.yh.controller
 * @version: 1.0
 */
@Controller
public class UserController {
    @Autowired
    UserService userService;

    @RequestMapping("/all")
    @ResponseBody
    public List<User> findAll() {
        return userService.findAll();
    }

    @RequestMapping("/{uid}")
    @ResponseBody
    public User findAByUid(@PathVariable("uid") int uid){
        return   userService.findByUid(uid);
    }

    @GetMapping("/allData")
    public String all(ModelMap model) {
        // 查询用户
        List<User> users = this.userService.findAll();
        // 放入模型
        model.addAttribute("users", users);
        // 返回模板名称（就是classpath:/templates/目录下的html文件名）
        return "users";
    }


}
